<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 16/5/5
 * Time: 下午4:39
 */
class AccountController extends BaseController{

    public function pending_order(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'order_id' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $order_id = Input::get('order_id');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            $response = Account::pending_order($order_id);
            
        } while (false);
        Log::info("info", array("system" => "account" ,"event" => "pending_order", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function custom_service_credit(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'user_id' => 'required',
                'amount' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $user_id = Input::get('user_id');
            $amount = Input::get('amount');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            if(Account::custom_service_credit($user_id,$amount)){
                $response = array(
                    'code' => 0,
                    'msg' => 'ok',
                    'result' => array(
                        'user_id' => $user_id,
                        'amount' => $amount,
                    )
                );
            }else{
                $response = array(
                    'code' => -1,
                    'msg' => 'error',
                    'result' => ''
                );
            }
        } while (false);
        Log::info("info", array("system" => "account" ,"event" => "custom_service_credit", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    public function custom_service_recharge(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'user_id' => 'required',
                'amount' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $user_id = Input::get('user_id');
            $amount = Input::get('amount');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            if(Account::custom_service_recharge($user_id,$amount)){
                $response = array(
                    'code' => 0,
                    'msg' => 'ok',
                    'result' => array(
                        'user_id' => $user_id,
                        'amount' => $amount,
                    )
                );
            }else{
                $response = array(
                    'code' => -1,
                    'msg' => 'error',
                    'result' => ''
                );
            }
        } while (false);
        Log::info("info", array("system" => "account" ,"event" => "custom_service_recharge", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
}